angular.module('mamApp').controller('albumOverviewController', ['$scope', 'reportManager', '$state', 'ImsAlert','paramsManager','api',
    function ($scope, reportManager, $state, ImsAlert,paramsManager,api) {

        $scope.search = {
            status: $state.params.status,
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            startTime: $state.params.startTime || null,
            endTime: $state.params.endTime || null,
            "X-Auth-Token":$scope.userInfo.token
        };

        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        };

        $scope.rangeDate = {
            startDate: $scope.search.startTime ? moment($scope.search.startTime).format('X') : null,
            endDate: $scope.search.endTime ? moment($scope.search.endTime).format('X') : null,
            onSelected: function (data, scope) {  //时间选择确认事件
                $scope.search.startTime = data.startDate ? moment(new Date(parseFloat(data.startDate) * 1000)).format("YYYY-MM-DD") : null;
                $scope.search.endTime = data.endDate ? moment(new Date(new Date(parseFloat(data.endDate) * 1000))).format("YYYY-MM-DD") : null;
                $scope.search.pageNo=1;
                $state.go($state.current.name, $scope.search);

            }
        };

        reportManager.albumList([$scope.search.pageNo, $scope.search.pageSize],$scope.search).then(function (result) {
            $scope.dataList = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;

            var albumData = result.data.imgList;
            var tmp=[];
            var duration=[];

            if(albumData){
                tmp= [{value: albumData.albumAlready, name: "已通过"}, {value: albumData.albumNot, name: "未通过"},
                    {value: albumData.albumPending, name: "待审核"}];
                duration = [{value: albumData.alreadyTime, name: "已通过"}, {value: albumData.notTime, name: "未通过"},
                    {value: albumData.pendingTime, name: "待审核"}];
            }else{
                tmp= [{value: 0, name: "已通过"}, {value:0, name: "未通过"},
                    {value: 0, name: "待审核"}];
                duration= [{value: 0, name: "已通过"}, {value:0, name: "未通过"},
                    {value: 0, name: "待审核"}];
            }
            albumDataInit(tmp);
            durationDataInit(duration)

        });

        //饼图

        function albumDataInit(data) {
            $scope.albumOption = {
                title: {
                    text: ' 专辑审核',
                    x: 'center',
                    textStyle:{
                        fontSize:16,
                        fontWeight:500,
                        color:'#000',
                        fontFamily:'Microsoft Yahei',
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['已通过', '未通过', '待审核']
                },
                series: [
                    {
                        name: '专辑审核',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data,

                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        color:['#4285f4', '#ea4335','#fbbc05']
                    }
                ]
            };
        }

        function durationDataInit(data) {
            $scope.durationOption = {
                title: {
                    text: ' 时长审核',
                    x: 'center',
                    textStyle:{
                        top:100,
                        fontSize:16,
                        fontWeight:500,
                        color:'#000',
                        fontFamily:'Microsoft Yahei',
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'left',
                    data: ['已通过', '未通过', '待审核']
                },
                series: [
                    {
                        name: '时长审核',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data,

                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        color:['#4285f4', '#ea4335','#fbbc05']
                    }
                ]
            };
        }

        //下载
        $scope.downHref=api+"/cp/exportAlbumSummary"+paramsManager.query($scope.search);

    }])


